#!/usr/bin/env node

//类
const Koa = require('koa');

const app = new Koa();

app.use(async (ctx,next)=>{ //M-logger
  const start = Date.now();
  await next();
  const end = Date.now();
  const cost = end-start;

  console.log(`${ctx.method} ${ctx.path} ${cost}ms`);  
});


app.use((ctx,next)=>{ //M-ms
  const start = Date.now();
  next();
  const end = Date.now();
  ctx.cost = end-start;
});

app.use((ctx,next)=>{ //M-hello中间件
    ctx.body = 'hello world';
 
});

app.listen(8080);

console.log('hello koa2');
